import os
def write(w,h):
    f = open("diagram.txt",'w+')
    matrix = [[" " for x in range(w)] for x in range(h)]
    for x in range(h):
        for y in range(w):
            matrix[x][0]=matrix[x][w-1]=matrix[0][y]=matrix[h-1][y] ="*"
            f.write(" "+str(matrix[x][y]))
            if y == w-1:
                f.write("\n")
    f.close()
    
def normalizeParam(**kargs):
    ddd = dict(**kargs)
    print(sorted(ddd.keys()))
    
        
        
import string
from lxml import etree

class TplFactory():

    def transform(self, xml, tpl, *args, **kargs):
        try:
            with open(tpl) as text:
                content = string.Template(text.read()).safe_substitute(kargs)
            content = isinstance(content) and content.encode('utf-8') or content
            self._getLogger().info(self, "transform|evaluate tpl template: " + str(tpl))
            return (len(args) == 2) and self._save(content, args[0], args[1]) or content
        except:
            return self._getLogger().trace(self, "transform|cannot parse.")